package vista;
import java.awt.BorderLayout;
import java.awt.event.ActionListener;
import java.util.Vector;

import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.JTextField;

import javax.swing.WindowConstants;
import javax.swing.table.DefaultTableModel;
import javax.swing.table.TableModel;
import javax.swing.SwingUtilities;


/**
* This code was edited or generated using CloudGarden's Jigloo
* SWT/Swing GUI Builder, which is free for non-commercial
* use. If Jigloo is being used commercially (ie, by a corporation,
* company or business for any purpose whatever) then you
* should purchase a license for each developer using Jigloo.
* Please visit www.cloudgarden.com for details.
* Use of Jigloo implies acceptance of these licensing terms.
* A COMMERCIAL LICENSE HAS NOT BEEN PURCHASED FOR
* THIS MACHINE, SO JIGLOO OR THIS CODE CANNOT BE USED
* LEGALLY FOR ANY CORPORATE OR COMMERCIAL PURPOSE.
*/
public class VentanaLinea extends javax.swing.JFrame {
	private JPanel panLinea;
	private JButton btnSalir;
	private JLabel lblNombreLinea;
	private JTextField txtNombLinea;
	private JButton btnGuardar;
	private JTextField txtCodLinea;
	private JLabel lblCodigoLinea;
	private JButton btnCrear;
	private JTable tblLineasRe;
	private JLabel lblLineasReg;
	private JScrollPane sclLinea;
	private JLabel lblLinea;
	
	
	private static VentanaLinea instancia;

	public static  VentanaLinea getInstancia() {
		if (instancia == null)
			instancia = new VentanaLinea();
		else
			instancia.setTitle("Lineas");
		return instancia;
	}
	
	public VentanaLinea() {
		super();
		initGUI();
	}
	
	private void initGUI() {
		try {
			setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
			this.setTitle("Lineas de Investigacion");
			{
				panLinea = new Fondo("imagen.jpg");
				getContentPane().add(panLinea, BorderLayout.CENTER);
				panLinea.setLayout(null);
				panLinea.setPreferredSize(new java.awt.Dimension(551, 329));
				{
					lblLinea = new JLabel();
					panLinea.add(lblLinea);
					lblLinea.setText("LINEAS DE INVESTIGACION");
					lblLinea.setBounds(150, 12, 277, 35);
					lblLinea.setFont(new java.awt.Font("URW Palladio L",0,20));
				}
				{
					sclLinea = new JScrollPane();
					panLinea.add(sclLinea);
					sclLinea.setBounds(31, 113, 276, 204);
					{
						DefaultTableModel tblLineasReModel = 
								new DefaultTableModel(
										new String[][] {},
										new String[] { "Codigo", "Nombre"});
						tblLineasRe = new JTable();
						sclLinea.setViewportView(tblLineasRe);
						tblLineasRe.setModel(tblLineasReModel);
						tblLineasRe.setPreferredSize(new java.awt.Dimension(248, 179));
					}
				}
				{
					lblLineasReg = new JLabel();
					panLinea.add(lblLineasReg);
					lblLineasReg.setText("Lineas de Investigacion Registradas");
					lblLineasReg.setBounds(31, 71, 263, 24);
					lblLineasReg.setFont(new java.awt.Font("URW Palladio L",0,16));
				}
				{
					btnCrear = new JButton();
					panLinea.add(btnCrear);
					btnCrear.setText("Crear");
					btnCrear.setBounds(176, 345, 131, 22);
				}
				{
					btnSalir = new JButton();
					panLinea.add(btnSalir);
					btnSalir.setText("Salir");
					btnSalir.setBounds(415, 345, 122, 22);
				}
				{
					lblCodigoLinea = new JLabel();
					panLinea.add(lblCodigoLinea);
					lblCodigoLinea.setText("Codigo:");
					lblCodigoLinea.setBounds(325, 113, 65, 22);
					lblCodigoLinea.setFont(new java.awt.Font("URW Palladio L",0,16));
				}
				{
					lblNombreLinea = new JLabel();
					panLinea.add(lblNombreLinea);
					lblNombreLinea.setText("Nombre:");
					lblNombreLinea.setBounds(325, 147, 73, 25);
					lblNombreLinea.setFont(new java.awt.Font("URW Palladio L",0,16));
				}
				{
					txtCodLinea = new JTextField();
					panLinea.add(txtCodLinea);
					txtCodLinea.setBounds(398, 113, 139, 22);
				}
				{
					txtNombLinea = new JTextField();
					panLinea.add(txtNombLinea);
					txtNombLinea.setBounds(398, 148, 139, 22);
				}
				{
					btnGuardar = new JButton();
					panLinea.add(btnGuardar);
					btnGuardar.setText("Guardar");
					btnGuardar.setBounds(415, 295, 122, 22);
				}
			}
			pack();
			this.setSize(584, 421);
		} catch (Exception e) {
		    //add your error handling code here
			e.printStackTrace();
		}
	}
	
	//SETTERS Y GETTERS Y OBTENER STRING DEL TXT
	public String getTxtNombLinea() {
		return txtNombLinea.getText();
	}

	public void setTxtNombLinea(String txtNombLinea) { 
		this.txtNombLinea.setText(txtNombLinea);
	}

	public String getTxtCodLinea() {
		return txtCodLinea.getText();
	}

	public void setTxtCodLinea(String txtCodLinea) {
		this.txtCodLinea.setText(txtCodLinea);
	}
	
	//LISTENERS
	public void agregarListener(ActionListener action){
		btnSalir.addActionListener(action);
		btnCrear.addActionListener(action);
		btnGuardar.addActionListener(action);
	}

	//METODO MOSTRAR MENSAJE
		public void mostrarMensaje(String mensaje) {
			JOptionPane.showMessageDialog(this, mensaje);
		}
	
	//METODO PARA LIMPIAR LA TABLA
	public void limpiarTabla(){
		tblLineasRe.removeAll();
	}
	
	// METODO CARGAR LISTADO LINEAS REGISTRADAS
	public void cargarListado(Vector<String> lineas){
		DefaultTableModel tbl = (DefaultTableModel) this.tblLineasRe.getModel();
		tbl.addRow(lineas);
	}
	
	//METODO OBTENER INDICE FILA SELECCIONADA
	public int obtenerIndiceFila(){
		int fila = tblLineasRe.getSelectedRow();
		return fila;
		}
	
	//METODO OBTENER CANTIDAD DE FILAS DE LA TABLA
	public int obtenerCantidadFilasSeleccionados(){
		return this.tblLineasRe.getRowCount();
	}
	
	//METODO COMPONENTES INVISIBLES
	public void componentesHabilitados(boolean valor){
		txtCodLinea.setVisible(valor);
		txtNombLinea.setVisible(valor);
		lblCodigoLinea.setVisible(valor);
		lblNombreLinea.setVisible(valor);
		btnGuardar.setVisible(valor);
		}
	
	//METODO DESHABILITAR EDICION
	public void desahabilitarComponente(boolean valor){
		txtCodLinea.setEditable(valor);
	}
	
	//LIMPIAR CAMPOS
	public void LimpiarCampos()
	{
		txtCodLinea.setText("");
		txtNombLinea.setText("");
	}
}
